local sk__zhitian = fk.CreateSkill {

  name = "sk__zhitian",

  tags = { Skill.Compulsory, },

}



sk__zhitian:addEffect(fk.EventPhaseStart, {
  name = "sk__zhitian",
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__zhitian.name) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local generals = room:getNGenerals(3)
    if #generals == 0 then return end
    local skills = {}
    for i = 1, #generals, 1 do
      table.insert(skills, Fk.generals[generals[i]]:getSkillNameList(true))
    end
    local result = room:askForCustomDialog(player, sk__zhitian.name,
      "packages/utility/qml/ChooseGeneralSkillsBox.qml", {
      generals, skills, 1, 1, "#sk__zhitian-choice", false
    })
    room:returnToGeneralPile(generals)
    local skill = skills[1][1]
    if result ~= "" then
      skill = result[1]
    end
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
      "#sk__zhitian-choose:::"..skill, sk__zhitian.name, false)
    to = room:getPlayerById(to[1])
    if to ~= player and not player:isKongcheng() then
      room:moveCardTo(player:getCardIds("h"), Card.PlayerHand, to, fk.ReasonGive, sk__zhitian.name, nil, false, player)
    end
    if not to.dead then
      room:handleAddLoseSkills(to, skill, nil, true, false)
    end
    if not to.dead then
      room:loseHp(to, 1, sk__zhitian.name)
    end
  end,
})

return sk__zhitian